<template>
  <div>
    <el-dialog class="app-container" title="物品列表" width="60%" :visible.sync="visible" top="5vh" append-to-body>
      <el-table  highlight-current-row :border="true" ref="select" :data="productList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column type="index" width="55" align="center" label="序号" />
        <el-table-column label="物品名称" align="center" prop="productName" />
        <el-table-column label="物品类型" align="center" prop="productType"/>
        <el-table-column label="单位" align="center" prop="unit" />
        <el-table-column label="产品图片" align="center" prop="image" width="100" >
          <template slot-scope="scope">
            <image-preview :src="scope.row.image" :width="50" :height="50" />
          </template>
        </el-table-column>
        <el-table-column label="产品介绍" align="center" prop="introduce" />
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProduct } from "@/api/module/product";

export default {
  name: "selectProduct",
  data(){
    return{
      visible:false,
      productList:[],
      articleList:[],
      total:0,
      queryParams:{
        pageNum: 1,
        pageSize: 10,
      }
    }
  },
  created() {
    this.getList()
  },
  methods:{
    show(isMultiple){
      if (isMultiple) {
        this.isMultiple = isMultiple;
      }
      this.visible=true
    },
    getList(){
      listProduct().then(response=>{
        console.log(response)
        this.productList = response.rows;
        this.total = response.total;

      })
    },
    handleSelectionChange(value){
      console.log(value)
      if(value.length>0){
        if (!this.isMultiple || this.isMultiple != 1) {
          // this.productName=value[0]
          this.articleList=value[0]
          if (value.length > 1) {
            this.$refs.select.clearSelection();
            this.$refs.select.toggleRowSelection(value.pop());
          }
        }
      }
    },
    submitForm(){

      this.visible=false
      this.$emit('showArticle',this.articleList)
      this.$refs.select.clearSelection()
    },
    cancel(){
      this.$refs.select.clearSelection()
      this.visible=false
    }
  }
}
</script>

<style scoped>

</style>
